
import java.util.ArrayList;

public class EventQueue extends Avl<EventPoint> {

    protected void insertAVL(Node node, Node father, boolean left, EventPoint new_data) {
        if (node.isEmpty()) {
            node.data = new_data;
            node.left = new Node();
            node.right = new Node();
        } else if (node.data.compareTo(new_data) == 0) {
            EventPoint event = (EventPoint) node.data;
            merge(new_data.u_list, event.u_list);
            merge(new_data.l_list, event.l_list);
        } else if (node.data.compareTo(new_data) > 0) {
            insertAVL(node.right, node, false, new_data);
            super.equilibrate(node, father, left);
        } else if (node.data.compareTo(new_data) < 0) {
            insertAVL(node.left, node, true, new_data);
            super.equilibrate(node, father, left);
        }
    }

    private void merge(ArrayList<Line> from, ArrayList<Line> to) {
        for (Line line : from) {
            if (!to.contains(line)) {
                to.add(line);
            }
        }
    }
}
